<template>
    <div class="contain-box">
        <div class="col_left">
            <list class="list" :questionList="questionList" :locationObj="locationObj"
                  v-if="locationObj.type!=1"></list>
            <FREELIST class="list" :questionList="questionList" :locationObj="locationObj" v-else></FREELIST>
        </div>
        <div class="col_right">
            <dtl :questionList="questionList" :locationObj="locationObj" v-if="locationObj.type!=1"></dtl>
            <FREEDTL :questionList="questionList" :locationObj="locationObj" v-else></FREEDTL>
        </div>
    </div>
</template>

<script>
import list from './questionList'
import dtl from './questionDtl'
import FREELIST from './questionListFree'
import FREEDTL from './questionDtlFree'
import utils from '@/plugins/common/utils';

export default {
    name: 'index',
    components: {
        list,
        dtl,
        FREELIST,
        FREEDTL
    },
    data() {
        return {
            questionList: [],
            locationObj: {},
            sec_lab_name: 'P1',
            requestData: [{
                url: 'doFreeQuestionList',
                type: 1,
                data: {
                    sec_lab_name: ''

                }
            },
                {
                    url: 'doEnterTest',
                    type: 2,
                    data: {
                        test_type: '',
                        test_id: '',
                        batch_id: ''
                    }
                },
                {
                    url: 'doCreateZhiNengTest',
                    type: 4,
                    data: {
                        num: '',
                        ques_type: '',
                        hard: '',
                        test_name: '',
                        sec_lab_name: '',
                        batch_id: '',
                        course_id: '',
                    }
                }],
        }
    },
    mounted() {
        this.locationObj = utils.getQueryObject(location.href);
        let data, url;
        this.requestData.forEach(item => {
            if (item.type == this.locationObj.type) {
                data = item.data;
                url = item.url;
                if (this.locationObj.type == 1) {
                    data.sec_lab_name = this.locationObj.secName;
                } else if (this.locationObj.type == 2) {
                    data = {
                        test_type: this.locationObj.test_type,
                        test_id: this.locationObj.test_id,
                        batch_id: this.locationObj.batch_id
                    }
                } else if (this.locationObj.type == 4) {
                    data = {
                        num: this.locationObj.num,
                        ques_type: this.locationObj.ques_type,
                        hard: this.locationObj.hard,
                        test_name: this.locationObj.test_name,
                        sec_lab_name: this.locationObj.sec_lab_name,
                        batch_id: this.locationObj.batch_id,
                        course_id: this.locationObj.course_id,
                    }
                }
            }
        })

        this.$api.ajaxData({
            authorization: true,
            pathName: url,
            data: data,
            method: 'post'
        }).then(res => {
                if (this.locationObj.type == 4) {
                    this.locationObj.test_id = '';
                    // this.locationObj.test_id = res.obj.dan.length > 0 ? res.obj.dan[0].id : (res.obj.duo.length > 0 ? res.obj.duo[0].id : '');
                }
                this.questionList = [
                    {
                        type: '单选题',
                        quest: res.obj.dan
                    },
                    {
                        type: '多选题',
                        quest: res.obj.duo
                    }];
                if (this.questionList[0].quest.length > 0) {
                    this.questionList[0].quest[0].isFirst = true;
                    this.questionList[0].quest[this.questionList[0].quest.length - 1].isEnd = true;
                }
                if (this.questionList[1].quest.length > 0) {
                    this.questionList[1].quest[0].isFirst = true;
                    this.questionList[1].quest[this.questionList[1].quest.length - 1].isEnd = true;
                }
                localStorage.setItem('questionList', JSON.stringify(this.questionList))

            }
        )
// }

    }
}
</script>

<style scoped lang="scss">
.list {
    box-shadow: rgba(204, 204, 204, 0.498) 0px 0px 10px
}

.contain-box {
    display: flex;
    //min-height: 100vh;
    .col_left {
        //flex: 1;
        width: 250px;
    }

    .col_right {
        width: calc(100% - 255px);
        //flex:1;
        //min-width: 600px;
    }
}
</style>
